package com.caotv.wkreport.action;

import java.util.List;

import org.apache.struts2.ServletActionContext;
import javax.servlet.http.HttpServletRequest;
import com.caotv.wkreport.dao.User;
import com.caotv.wkreport.dbutils.UserTableTool;
import com.caotv.wkreport.utils.StringUtils;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 
 * @author cao
 * 
 */

public class ManagerUserAction extends ActionSupport {

	private List<User> listUsers = null;
	private User user = new User();

	public String execute() {
		listUsers = UserTableTool.getInstance().getAllUsers();
		return "success";
	}

	public String deleteUser() {
		HttpServletRequest request = ServletActionContext.getRequest();
		int id = Integer.parseInt(request.getParameter("id"));
		UserTableTool.getInstance().deleteUserById(id);
		listUsers = UserTableTool.getInstance().getAllUsers();
		return "success";
	}

	public String editUser() {
		HttpServletRequest request = ServletActionContext.getRequest();
		int id = Integer.parseInt(request.getParameter("id"));
		user = UserTableTool.getInstance().getUserById(id);
		return "success";
	}
	
	public String addUser(){
		return "success";
	}

	public List<User> getListUsers() {
		return listUsers;
	}

	public void setListUsers(List<User> listUsers) {
		this.listUsers = listUsers;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

}
